package com.yyx;

import com.yyx.pojo.entity.User;
import com.yyx.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class NowAppsAppApplication {

    public static void main(String[] args) {
        SpringApplication.run(NowAppsAppApplication.class, args);
    }

    @Autowired
    private UserRepository userRepository;

    @Bean
    public CommandLineRunner initAdminAccount() {
        return args -> {
            if (userRepository.findByUsername("admin") == null) {
                User admin = new User();
                admin.setUsername("admin");
                admin.setPassword("1234");
                admin.setRealName("李四管");
                admin.setRole("MANAGER");
                userRepository.save(admin);
            }
        };
    }

}
